(function (vc) {
    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addShopReturnAddressInfo: {
                addressId: '',
                name: '',
                link: '',
                address: '',
                seq: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('addShopReturnAddress', 'openAddShopReturnAddressModal', function () {
                $('#addShopReturnAddressModel').modal('show');
            });
        },
        methods: {
            addShopReturnAddressValidate() {
                return vc.validate.validate({
                    addShopReturnAddressInfo: $that.addShopReturnAddressInfo
                }, {
                    'addShopReturnAddressInfo.name': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "收货人名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "收货人名称太长"
                        },
                    ],
                    'addShopReturnAddressInfo.link': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "联系电话不能为空"
                        },
                        {
                            limit: "phone",
                            param: "",
                            errInfo: "联系电话格式错误"
                        },
                    ],
                    'addShopReturnAddressInfo.address': [
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "详细地址太长"
                        },
                    ],
                    'addShopReturnAddressInfo.seq': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "排序不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "排序不是有效数字"
                        },
                    ]
                });
            },
            saveShopReturnAddressInfo: function () {
                if (!$that.addShopReturnAddressValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.addShopReturnAddressInfo.shopId = vc.getCurrentCommunity().shopId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, $that.addShopReturnAddressInfo);
                    $('#addShopReturnAddressModel').modal('hide');
                    return;
                }
                vc.http.apiPost(
                    '/shopReturnAddress/saveShopReturnAddress',
                    JSON.stringify($that.addShopReturnAddressInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addShopReturnAddressModel').modal('hide');
                            $that.clearAddShopReturnAddressInfo();
                            vc.emit('shopReturnAddressManage', 'listShopReturnAddress', {});
                            vc.toast("添加成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            clearAddShopReturnAddressInfo: function () {
                $that.addShopReturnAddressInfo = {
                    name: '',
                    link: '',
                    address: '',
                    seq: ''
                };
            }
        }
    });
})(window.vc);
